
class MineScene extends core.BaseScene {
    private static _HasInited: boolean
    public static Init() {
        if (MineScene._HasInited) {
            return
        }
        MineScene._HasInited = true

        core.App.SceneManager.register(SceneConsts.Mine, new MineScene())
        //core.App.ControllerManager.register(ControllerConsts.GameOver, new GameOverControl())
        //core.App.ControllerManager.register(ControllerConsts.MainGame, new MainGameControl())
    }

    constructor() {
        super()
    }

    private _bg: TitleMap
    public get Background(): egret.DisplayObjectContainer {
        return this._bg
    }

    public onEnter(): void {
        super.onEnter()

        this._bg = new TitleMap()
        this._bg.initMap()
        LayerManager.Game_Bg.addChild(this._bg)
        this._bg.LookAt(0, 0)

        this.addLayerAt(LayerManager.Game_Bg, 0)
        this.addLayerAt(LayerManager.UI_Game, 1)

        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this)
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTapBegin, this, true)
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_END, this.onTapEnd, this)
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.onTapEnd, this)
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.onTapEnd, this)
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTapMove, this)

        LayerManager.UI_Game.touchEnabled = true

        {
            //测试代码
            let map = new MineMap(12800, 7960, MineBlockWidth, MineBlockHeight, this._bg)

            map.SetCell(100, 101, CellState.MarkBoom)
            map.SetCell(0, 0, CellState.MarkQuote)
            map.SetCell(3, 3, CellState.Open)
            map.SetCell(4, 4, CellState.MarkBoom)
            map.SetCell(10, 10, CellState.MarkBoom)
        }
    }

    public onExit(): void {
        super.onExit()
    }

    public enterFrame(time: number) {
    }

    private _lookX: number = 0
    private _lookY: number = 0
    private _moveX: number = 0
    private _moveY: number = 0
    private _tapMove: boolean = false
    private onTap(e: egret.TouchEvent) {
        console.log("onTap:")
    }
    private onTapBegin(e: egret.TouchEvent) {
        console.log("onTapBegin" + e.target)
    }
    private onTapEnd(e: egret.TouchEvent) {
        console.log("onTapEnd")
        this._tapMove = false
    }
    private onTapMove(e: egret.TouchEvent) {
        console.log("onTapMove")
        //console.log("local:" + e.localX + "," + e.localY)
        //console.log("stage:" + e.stageX + "," + e.stageY)
        if (this._tapMove == false) {
            this._tapMove = true
            this._moveX = e.localX + this._bg.LookX
            this._moveY = e.localY + this._bg.LookY
        }
        console.log("delta:" + (this._moveX - e.localX) + "," + (this._moveY - e.localY))


        this._bg.LookAt(this._moveX - e.localX, this._moveY - e.localY)
    }
}